package yc.star.system.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import yc.star.common.controller.BaseController;
import yc.star.common.domain.AppResult;
import yc.star.common.domain.TableDataInfo;
import yc.star.system.domain.question.dto.QuestionAddDTO;
import yc.star.system.domain.question.dto.QuestionEditDTO;
import yc.star.system.domain.question.dto.QuestionQueryDto;
import yc.star.system.domain.question.vo.QuestionDetailVO;
import yc.star.system.domain.question.vo.QuestionVO;
import yc.star.system.service.IQuestionService;

import java.util.List;


@RequestMapping("/question")
@Tag(name = "题目接口")
@RestController
public class QuestionController extends BaseController {

    @Autowired
    private IQuestionService questionService;

    @GetMapping("/list")
    public TableDataInfo list (QuestionQueryDto questionQueryDto) {
        List<QuestionVO> questionVOList = questionService.list(questionQueryDto);
        return getTableDataInfo(questionVOList);
    }

    @PostMapping("/add")
    public AppResult<Void> add (@RequestBody QuestionAddDTO questionAddDTO) {
        return toAppResult(questionService.add(questionAddDTO));
    }

    @GetMapping("/detail")
    public AppResult<QuestionDetailVO> detail (Long questionId) {
        return AppResult.success(questionService.detail(questionId));
    }

    @PutMapping("/edit")
    public AppResult<Void> edit (@RequestBody QuestionEditDTO questionEditDTO) {
        int rows = questionService.edit(questionEditDTO);
        return toAppResult(rows);
    }

    @DeleteMapping("/delete")
    public AppResult<Void> delete (Long questionId) {
        int rows = questionService.delete(questionId);
        return toAppResult(rows);
    }

}